package order.server.conreoller;

import common.server.aop.AopSign;
import common.server.controller.BaseController;
import common.server.entity.InsideRequestMessage;
import common.server.entity.InsideResponseMessage;
import common.server.utils.Contants;
import common.server.utils.ThreadLocalTraceUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import order.api.entity.param.OrderParam;
import order.api.entity.result.OrderPojo;
import order.api.respcode.OrderRespCode;
import order.api.service.IOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Title: OrderController
 * @ProjectName com-bigwavn-group
 * @Description: 商品管理（客户端）
 * @author: wangweitao 1749343503@qq.com
 * @date: 2019/5/29 14:45
 * @version: V1.0.0
 */
@AopSign
@Api(tags = "orderController", description = "订单管理")
@RestController
@RequestMapping(path = "/order/IOrderService")
public class OrderController extends BaseController {

    // 系统日志输出对象定义
    private static final Logger logger = LoggerFactory.getLogger(OrderController.class);

    // 统计日志输出对象定义
    private static final Logger loggerOrder = LoggerFactory.getLogger("order-log");

    @Autowired
    private IOrderService OrderService;

    @ApiOperation("商品列表查询")
    @ResponseBody
    @PostMapping(path = "/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public InsideResponseMessage<List<OrderPojo>> getOrderList(@RequestBody InsideRequestMessage<OrderParam> req) {
        Map<String,Object> headerMap = getFeignHeaderMap();

        String bussCode = (String)headerMap.get(Contants.DEFATE_SERVICE_CODE_NAME);
        String trace = (String)headerMap.get(Contants.DEFATE_TRACE_NAME);

        ThreadLocalTraceUtil.setTrace(trace);
        ThreadLocalTraceUtil.setBussCode(bussCode);

        logger.info("trace="+trace+"查询商品中心-商品列表-getOrderLists is starting("+bussCode+").........");
        logger.info("trace="+trace+"查询商品中心-商品列表-getOrderLists请求参数:"+req);
        InsideResponseMessage<List<OrderPojo>> result = new InsideResponseMessage<List<OrderPojo>>();
        try {

            result = OrderService.getOrderList(trace,req);

            logger.info("trace="+trace+"查询商品中心-商品列表-getOrderLists is success......");
            logger.info("trace="+trace+"查询商品中心-商品列表-getOrderLists返回编码及描述:"+result.getRetCode()+": "+result.getRetDesc());
            logger.info("trace="+trace+"查询商品中心-商品列表-getOrderLists返回结果:"+result.getRspBody());
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("trace="+trace+"商品中心-商品列表查询异常:"+e.getMessage(),e);
            result.setRetCode(OrderRespCode.COMM_ERROR.getCode());
            result.setRetDesc(OrderRespCode.COMM_ERROR.getDesc());
        }
        return result;
    }

}
